var EventEmitter = require('events')

//EventEmitter
//原型方法
//Emit 发送事件
// on 监听事件
// once 监听一次事件

//ES6继承
class MyEvent extends EventEmitter{}

//ES5继承
function MyEmitter(){
    EventEmitter.call(this)
}

// 实例化原型解决ES5继承无法继承原型的问题
MyEmitter.prototype = new EventEmitter()

//复制原型对象解决ES5无法继承原型问题
// for(var i in EventEmitter.prototype){
//     MyEmitter.prototype[i]=EventEmitter
//     .prototype[i]
// }

const p1 = new MyEmitter()

p1.on("todosome",msg=>{
    console.log(msg)
})

p1.emit("todosome","┗|｀O′|┛ 嗷~~")
p1.emit("todosome","芜湖~")

p1.once("faq",msg=>{
    console.log(msg)
})

p1.emit("faq","天街巡游")
p1.emit("faq","剑光如我")
p1.emit("faq","斩尽牛杂")